<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>

</head>

<body>


    <button id="btn1">全选</button>
    <button id="btn2">全不选</button>
    <button id="btn3">反选</button><br>
    <div>
        <input type="checkbox">
        <input type="checkbox">
        <input type="checkbox">
        <input type="checkbox">
        <input type="checkbox">
        <input type="checkbox">
        <input type="checkbox">
        <input type="checkbox">
        <input type="checkbox">
        <input type="checkbox">
    </div>



    <script>
        // 获取元素 绑定标签名
        var btn = document.getElementsByTagName("button");
        var inputs = document.getElementsByTagName("input");

        for (var i = 0; i < btn.length; i++) {
            btn[i].onclick = function() {
                if (this.innerHTML === "全选") {
                    for (var j = 0; j < inputs.length; j++) {
                        inputs[j].checked = true;
                    }

                } else if (this.innerHTML === "反选") {
                    for (var j = 0; j < inputs.length; j++) {
                        inputs[j].checked = !inputs[j].checked;
                    }
                } else if (this.innerHTML === "全不选") {
                    for (var j = 0; j < inputs.length; j++) {
                        inputs[j].checked = false;
                    }


                }
            }
        }
    </script>
</body>

</html>